package demo.sciau.votesystem.util;

import demo.sciau.votesystem.entity.VO.ResultEnumVO;
import demo.sciau.votesystem.entity.VO.ResultVO;
import org.springframework.stereotype.Component;

/**
 * @Author beifengtz
 * @Date Created in 14:38 2018/10/28
 * @Description:
 */
@Component
public class ResultVOUtil {

    /**
     * 成功
     * */
    public ResultVO success(){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(ResultEnumVO.SUCCESS.getCode());
        resultVO.setMsg(ResultEnumVO.SUCCESS.getMsg());
        resultVO.setData(null);
        return resultVO;
    }

    public ResultVO success(String msg){
        ResultVO resultVO = this.success();
        resultVO.setMsg(msg);
        return resultVO;
    }
     public ResultVO success(Object data){
        ResultVO resultVO = this.success();
        resultVO.setData(data);
        return resultVO;
     }
     public ResultVO success(String msg,Object data){
        ResultVO resultVO = this.success(data);
        resultVO.setMsg(msg);
        return resultVO;
     }

    /**
     * 未知错误
     * */
    public ResultVO unknowError(){
        return new ResultVO(ResultEnumVO.UNKNOW_ERROR.getCode(),
                ResultEnumVO.UNKNOW_ERROR.getMsg());
    }

    public ResultVO unknowError(String msg){
        ResultVO resultVO = this.unknowError();
        resultVO.setMsg(msg);
        return resultVO;
    }

    public ResultVO unknowError(Object data){
        ResultVO resultVO = this.unknowError();
        resultVO.setData(data);
        return resultVO;
    }

    public ResultVO unknowError(String msg,Object data){
        ResultVO resultVO = this.unknowError(data);
        resultVO.setMsg(msg);
        return resultVO;
    }

    /**
     * 参数错误
     * */
    public ResultVO paramError() {
        return new ResultVO(ResultEnumVO.PARAM_ERROR.getCode(),
                ResultEnumVO.PARAM_ERROR.getMsg());
    }
    public ResultVO paramError(String msg) {
        ResultVO resultVO = this.paramError();
        resultVO.setMsg(msg);
        return resultVO;
    }

    /**
     * 资源不存在
     * */
    public ResultVO resourceNotFound() {
        return new ResultVO(ResultEnumVO.RESOURCE_NOT_FOUND.getCode(),
                ResultEnumVO.RESOURCE_NOT_FOUND.getMsg());
    }

    public ResultVO resourceNotFound(String msg) {
        ResultVO resultVO = this.resourceNotFound();
        resultVO.setMsg(msg);
        return resultVO;
    }
}
